package com.tz.cartelo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.tz.cartelo.R;
import com.tz.cartelo.model.GoodsList;
import com.tz.cartelo.model.GoodsPictureTail;
import com.tz.cartelo.util.CommonUtils;

import java.util.List;


/**
 * Created by ok on 2016/9/18.
 */
public class GoodsDetailsAdapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    private List<GoodsPictureTail> mGoodsPictureTailList;
    private Context mContext;
    private int mImgWidth, mImgHeight;

    public GoodsDetailsAdapter(Context context, List<GoodsPictureTail> goodsPictureTailList) {
        mLayoutInflater = LayoutInflater.from(context);
        mContext = context;
        mGoodsPictureTailList = goodsPictureTailList;
//        setImgSize();
    }

    private void setImgSize() {
        mImgWidth = (CommonUtils.getScreenWidth(mContext) - 3 * mContext.getResources().getDimensionPixelOffset(R.dimen.margin_10)) / 2;
        mImgHeight = mImgWidth;
        //+ mContext.getResources().getDimensionPixelOffset(R.dimen.margin_5)
    }

    @Override
    public int getCount() {
        return mGoodsPictureTailList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = mLayoutInflater.inflate(R.layout.item_goods_details_adapter, null);
            holder = new ViewHolder();
            holder.itemGoodsDetailsImg = (ImageView) view.findViewById(R.id.item_goods_details_img);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
//        ImageLoader.getInstance().displayImage("drawable://" + R.mipmap.ic_holder_list, holder.itemGoodsDetailsImg, CommonUtils.optionsList());
        ImageLoader.getInstance().displayImage(mGoodsPictureTailList.get(i).getFileUrl(), holder.itemGoodsDetailsImg, CommonUtils.optionsList());
        return view;
    }

    private class ViewHolder {
        ImageView itemGoodsDetailsImg;
    }

}
